package jsp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author MissChen
 * @date 2024年05月13日 15:12
 */
// @WebServlet("/show")
@WebServlet("/show/*")
public class ShowServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String uri=request.getRequestURI();
        System.out.println("uri:"+uri);// /web/show/a/test02

        String contextPath=request.getContextPath();
        System.out.println("contextPath:"+contextPath);// /web

        String servletPath=request.getServletPath();//  /show
        System.out.println("servletPath:"+servletPath);

        String path=uri.substring((contextPath+servletPath).length());//   "/web/show/a/test02".substring(9)
        System.out.println("path:"+path);//    /a/test02


        request.getRequestDispatcher("/WEB-INF"+path+".jsp").forward(request,response);

    }
}
